﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.DS
{
    public static partial class status
    {
        public static dynamic cleanDSProblemStatus(int eid, int pid)
        {
            var sql = new Sql.SqlDataContext();
            if (!sql.DSProblem.Any(row => row.eid == eid && row.pid == pid)) return new
            {
                success = false,
                msg = "题目不存在"
            };
            // Delete Status
            var sts = sql.DSStatus.Where(row => row.eid == eid && row.pid == pid);
            sql.DSStatus.DeleteAllOnSubmit(sts);

            // Reset ProblemStatistics
            var ps = sql.DSProblemStatistics.FirstOrDefault(row => row.eid == eid && row.pid == pid);
            if (ps != null) ps.accept =  ps.submit = 0;

            // Delete Solve
            sql.DSSolve.DeleteAllOnSubmit(sql.DSSolve.Where(row => row.eid == eid && row.pid == pid));

            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
